package com.pai4j.pgc.dao.community;
import com.pai4j.pgc.entity.community.MessageEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 *
 *
 * @author: CYM-pai
 * @date: 2025/10/31 11:20
 **/

@Repository
public interface IMessageDAO extends JpaRepository<MessageEntity, Long>, JpaSpecificationExecutor<MessageEntity> {

    @Modifying
    @Transactional
    @Query(value = "update pai4j_message m set m.state = 1 where m.to_user_id = ?1 and m.category = ?2", nativeQuery = true)
    void updateUserMessageReadState(String toUserId, String category);


    List<MessageEntity> findAllByToUserIdAndCategoryOrderByIdAsc(String toUserId, String category);
}
